import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useCounterStore = defineStore(
	'counter',
	() => {
		// 定义 state
		const count = ref(0)
		const info = ref('')

		// 定义 getters
		const double = computed(() => count.value * 2)

		// 定义 actions
		const increment = () => {
			count.value++
			info.value += '~'
		}

		const decrement = () => {
			count.value--
		}

		const decrementPlus = (num: number) => {
			count.value += num
		}

		// 千万不要忘记这里要 return
		return { count, double, increment, decrement, decrementPlus, info }
	},
	// { unistorage: true } // true 当前文件中的状态变量都会保存到 硬盘中
	{
		unistorage: {
			key: 'doctor-key', // 保存到缓存中的键
			paths: ['count'], // 需要缓存的值，如果希望部分缓存的话，可以这么写
		},
	}
)
